/*
 * Tf: a unit test framework for C
 * Copyright (C) 2012 zrezek at gmail.com
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3.0 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#include "money.h"
#include "tf.h"

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
static money_t money100Eur;
static money_t money200Eur;
static money_t money100Gbp;

static void money_setup()
{
    money_init(&money100Eur, "EUR", 100.0);
    money_init(&money200Eur, "EUR", 200.0);
    money_init(&money100Gbp, "GBP", 100.0);
}

TF_BEGIN_TEST(initializer_test)
{
    money_t money;

    TF_REQUIRE_EQ(money_get_ammount(&money100Eur), 100.0);
    TF_REQUIRE_STR_EQ(money_get_currency(&money100Eur), "EUR");

    TF_REQUIRE_EQ(money_get_ammount(&money200Eur), 200.0);
    TF_REQUIRE_STR_EQ(money_get_currency(&money200Eur), "EUR");

    TF_REQUIRE_EQ(money_get_ammount(&money100Gbp), 100.0);
    TF_REQUIRE_STR_EQ(money_get_currency(&money100Gbp), "GBP");
}
TF_END_TEST

TF_BEGIN_TEST(equality_test)
{
    // same value & currency
    TF_REQUIRE(!money_cmp(&money100Eur, &money100Eur));

    // same currencies, different values
    TF_REQUIRE(money_cmp(&money100Eur, &money200Eur));

    // same values, different currencies
    TF_REQUIRE(money_cmp(&money100Eur, &money100Gbp));
}
TF_END_TEST

TF_BEGIN_TEST(add_test)
{
    money_t m;

    // add values in the same currencies
    TF_REQUIRE(money_add(&m, &money100Eur, &money200Eur));
    TF_REQUIRE_STR_EQ(money_get_currency(&m), "EUR");
    TF_REQUIRE_EQ(money_get_ammount(&m), 300);

    // can't add values in different currencies
    TF_REQUIRE(!money_add(&m, &money100Eur, &money100Gbp));
}
TF_END_TEST

TF_BEGIN_FIXTURE(/tf/example/, money)
{
    TF_TEST(initializer_test);
    TF_TEST(equality_test);
    TF_TEST(add_test);

    TF_SETUP(money_setup);

    // no teardown needed for this fixture
}
TF_END_FIXTURE

